<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form action="" id="form1" method="get">
    <input type="text" name="userName" placeholder="请输入用户名">
    <input type="password" name="password" placeholder="请输入密码">
    <input type="submit" name="submit" onclick="submitOnclick()">
</form>
<script type="text/javascript">
   function submitOnclick(){
      var form1=document.getElementById('form1');
      if(form1.userName.value==''){
          alert('用户名不能为空');
          form1.userName.focus();
          return ;
      }
      if(form1.userName.value.length<6||form1.userName.value>10){
          alert('用户名不能少于六个字符，不能超过十个字符');
          form1.userName.focus();
          return ;
      }
      if(form1.password.value==''){
          alert('密码不能为空');
          form1.password.focus();
          return ;
      }
       if(form1.password.value.length<6||form1.password.value>10){
           alert('密码不能少于六个字符，不能超过十个字符');
           form1.password.focus();
           return ;
       }
       var str='用户名：'+form1.userName.value+'<br>'+'密码：'+form1.password.value;
       document.write(str);

   }
</script>
</body>
</html>